package com.IR.product.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.IR.oss.util.MyDateProcessor;
import com.IR.product.service.BProductCommentBIZ;
import com.IR.shop.po.Productcomment;

import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;

@Controller
public class BProductCommentAction {

	@Resource
	private BProductCommentBIZ biz;
	
	
	/*分页展示评论*/
	@RequestMapping(value="/showProCommentPage.do")
	public void showProCommentPage(int pagenow,int pagesize,int proid,HttpServletResponse response){
		
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		List<Productcomment> l=biz.showProCommentPage(pagenow, pagesize,proid);
		try {
			PrintWriter out = response.getWriter();		
			MyDateProcessor mydate=new MyDateProcessor("yyyy-MM-dd HH:mm:ss");
			JsonConfig config=new JsonConfig();
			config.registerJsonValueProcessor("pcdate", mydate);		
			String str = JSONArray.fromObject(l,config).toString();
			out.println(str);
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}
	@RequestMapping(value="/showProCommentPage2.do")
	public void showProCommentPage2(HttpServletRequest request,HttpServletResponse response){
		
		response.setHeader("Access-Control-Allow-Origin", "*");
		response.setCharacterEncoding("utf-8");
		Integer pagesize=new Integer(request.getParameter("pagesize"));
		Integer pagenow=new Integer(request.getParameter("pagenow"));
		List<Productcomment> l=biz.showProCommentPage2(pagenow, pagesize);
		try {
			PrintWriter out = response.getWriter();		
			MyDateProcessor mydate=new MyDateProcessor("yyyy-MM-dd HH:mm:ss");
			JsonConfig config=new JsonConfig();
			config.registerJsonValueProcessor("pcdate", mydate);		
			String str = JSONArray.fromObject(l,config).toString();
			out.println(str);
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}
}
